using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;

using Microsoft.SqlServer.Management.Common;
using System.Collections;
namespace Quanly_dethi.Class
{
    class csC_DapanCH
    {
        private ketnoi kn;

        public ketnoi Kn
        {
            get { return kn; }
            set { kn = value; }
        }
        private string databasename;

        public string Databasename
        {
            get { return databasename; }
            set { databasename = value; }
        }
        public csC_DapanCH()
        {
            Kn = new ketnoi();
            databasename = "";
        }
        public csC_DapanCH(string servername, string user, string pass, string dbname)
        {
            Kn = new ketnoi(servername ,user, pass);
            databasename = dbname;
        }
        public DataTable Sellect()
        { 
            Database db=Kn._Server.Databases[databasename];
            return db.ExecuteWithResults("select * from DapAnCH where Xoa='0'").Tables[0];
        }
        public DataTable Sellect(int ma)
        {
            string s = "select  * from DapAnCH where MaCH=" + ma + "";
            Database db = Kn._Server.Databases[databasename];
            return db.ExecuteWithResults(s).Tables[0];
        }
       
        public void insert(int mach, string noidung, int dapandung,string noidung2, int dapan2, string noidung3, int dapan3, string noidung4, int dapan4)
        {
            try
            {
                Database db = Kn._Server.Databases[databasename];
                string s = "insert into DapAnCH(MaCH, Noidungcautraloi,DapAnDung) values(N'" + mach + "',N'" + noidung + "',N'" + dapandung + "')";
                s += "insert into DapAnCH(MaCH, Noidungcautraloi,DapAnDung) values(N'" + mach + "',N'" + noidung2 + "',N'" + dapan2 + "')";
                s += "insert into DapAnCH(MaCH, Noidungcautraloi,DapAnDung) values(N'" + mach + "',N'" + noidung3 + "',N'" + dapan3 + "')";
                s += "insert into DapAnCH(MaCH, Noidungcautraloi,DapAnDung) values(N'" + mach + "',N'" + noidung4 + "',N'" + dapan4 + "')";
                db.ExecuteWithResults(s);
            }
            catch (System.Exception e)
            {
                MessageBox.Show(e.ToString());
            }
           

        }
       public void suadapan(int mach, string noidung, int ma1,int ma2, int ma3, int ma4,int dapandung,string noidung2, int dapan2, string noidung3, int dapan3, string noidung4, int dapan4)
       {
           try
           {
               Database db = Kn._Server.Databases[databasename];
               string s = "update DapAnCH set Noidungcautraloi=N'" + noidung + "',DapAnDung=N'" + dapandung + "' where MaCH='" + mach + "' and MaDACH='" + ma1 + "'";
               s += "update DapAnCH set Noidungcautraloi=N'" + noidung2 + "',DapAnDung=N'" + dapan2 + "' where MaCH='" + mach + "' and MaDACH='" + ma2 + "'";
               s += "update DapAnCH set Noidungcautraloi=N'" + noidung3 + "',DapAnDung=N'" + dapan3 + "' where MaCH='" + mach + "' and MaDACH='" + ma3 + "'";
               s += "update DapAnCH set Noidungcautraloi=N'" + noidung4 + "',DapAnDung=N'" + dapan4 + "' where MaCH='" + mach + "' and MaDACH='" + ma4 + "'";
               db.ExecuteWithResults(s);
           }
           catch (System.Exception e)
           {
               MessageBox.Show(e.ToString());
           }
          
       }
      
    }
}
